package com.ktjy.web;



import com.ktjy.entity.User;
import com.ktjy.service.UserService;
import com.ktjy.service.impl.UserServiceImpl;
import my.framework.anno.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginController {
    @RequestMapping("/login")
    public String login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //调用Service登录方法
        UserService userService=new UserServiceImpl();
        User user=userService.login(username,password);
        if(user!=null){
            //保存用户信息到Session
            request.getSession().setAttribute("loginUser",user);
            //跳转首页
            if(user.getUserIsAdmin()){
                //进入管理员页面
                return "redirect:/do/list";
            }else{
                //进入普通用户界面
                //request.getRequestDispatcher("/actionList.jsp").forward(request,response);
            }
        }
        return "redirect:/fail.jsp";//重定向
    }
}
